﻿using UM_SERVER.ProcessModel;
using UM_SERVER.Packet.InPacket;
using UM_SERVER.Net;
using System.Text;
using System;

namespace UM_SERVER.ProcessModel
{
    class UpdateProcessModel : Model
    {
        /// <summary>
        ///     回复指定用户修改个性签名成功包
        /// </summary>
        /// <param name="inpackage" type="UM_SERVER.Packet.InPacket.ModifyProdPacket">
        ///     <para>
        ///         个性签名修改请求包
        ///     </para>
        /// </param>
        public static void ACK_SucessfulModifyProd(ModifyProdPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ModifyState = BitConverter.GetBytes(true);
            byte[] packagebody = new byte[Username.Length + 5];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ModifyState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyModifyProd",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_MODIFY_PROD_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复指定用户修改个性签名失败包
        /// </summary>
        /// <param name="inpackage" type="UM_SERVER.Packet.InPacket.ModifyProdPacket">
        ///     <para>
        ///         个性签名修改请求包
        ///     </para>
        /// </param>
        public static void ACK_FailModifyProd(ModifyProdPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ModifyState = BitConverter.GetBytes(false);
            byte[] packagebody = new byte[Username.Length + 5];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ModifyState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyModifyProd",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_MODIFY_PROD_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复更新指定用户挂起信息成功包
        /// </summary>
        /// <param name="inpackage" type="UM_SERVER.Packet.InPacket.UpdateUserInfoPacket">
        ///     <para>
        ///         用户挂起信息请求包
        ///     </para>
        /// </param>
        public static void ACK_SucessfulUpdateUserInfo(UpdateUserInfoPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] DbFiled = Encoding.Default.GetBytes(inpackage.GetDbFiled());
            byte[] DbFiledLength = BitConverter.GetBytes(DbFiled.Length);
            byte[] UpdateState = BitConverter.GetBytes(true);
            byte[] packagebody = new byte[Username.Length + DbFiled.Length + 9];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(DbFiledLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(DbFiled, 0, packagebody, Offset, DbFiled.Length);
            Offset += DbFiled.Length;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyUpdateChanage" + inpackage.GetDbFiled().Trim(),
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_UPDATE_USERINFO,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复更新指定用户挂起信息失败包
        /// </summary>
        /// <param name="inpackage" type="UM_SERVER.Packet.InPacket.UpdateUserInfoPacket">
        ///     <para>
        ///         用户挂起信息请求包
        ///     </para>
        /// </param>
        public static void ACK_FailUpdateUserInfo(UpdateUserInfoPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] DbFiled = Encoding.Default.GetBytes(inpackage.GetDbFiled());
            byte[] DbFiledLength = BitConverter.GetBytes(DbFiled.Length);
            byte[] UpdateState = BitConverter.GetBytes(false);
            byte[] packagebody = new byte[Username.Length + DbFiled.Length + 9];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(DbFiledLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(DbFiled, 0, packagebody, Offset, DbFiled.Length);
            Offset += DbFiled.Length;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyUpdateChanage" + inpackage.GetDbFiled().Trim(),
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_UPDATE_USERINFO,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复更新用户分组成功包
        /// </summary>
        /// <param name="inpackage">更新用户分组请求包</param>
        public static void ACK_SucessfulUpdateItem(UpdateItemPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ItemId = BitConverter.GetBytes(inpackage.GetItemId());
            byte[] UpdateState = BitConverter.GetBytes(true);
            byte[] packagebody = new byte[Username.Length + 9];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyUpdateItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_UPDATE_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复更新用户分组失败包
        /// </summary>
        /// <param name="inpackage">更新用户分组请求包</param>
        public static void ACK_FailUpdateItem(UpdateItemPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ItemId = BitConverter.GetBytes(inpackage.GetItemId());
            byte[] UpdateState = BitConverter.GetBytes(false);
            byte[] packagebody = new byte[Username.Length + 9];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyUpdateItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_UPDATE_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        // <summary>
        ///     回复添加用户分组成功包
        /// </summary>
        /// <param name="inpackage">添加用户分组请求包</param>
        /// <param name="ItemId">分组ID</param>
        public static void ACK_SucessfulAddItem(AddItemPacket inpackage, int itemId)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ItemKey = Encoding.Default.GetBytes(inpackage.GetItemKey());
            byte[] ItemKeyLength = BitConverter.GetBytes(ItemKey.Length);
            byte[] Session = Encoding.Default.GetBytes(inpackage.GetSessionCode());
            byte[] SessionLength = BitConverter.GetBytes(Session.Length);
            byte[] ItemId = BitConverter.GetBytes(itemId);
            byte[] UpdateState = BitConverter.GetBytes(true);

            byte[] packagebody = new byte[Username.Length + ItemKey.Length + Session.Length + 17];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ItemKeyLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(ItemKey, 0, packagebody, Offset, ItemKey.Length);
            Offset += ItemKey.Length;
            Array.ConstrainedCopy(SessionLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Session, 0, packagebody, Offset, Session.Length);
            Offset += Session.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyAddItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_ADD_NEW_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复添加用户分组失败包
        /// </summary>
        /// <param name="inpackage">添加用户分组请求包</param>
        /// <param name="ItemId">分组ID</param>
        public static void ACK_FailAddItem(AddItemPacket inpackage, int itemId)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] ItemKey = Encoding.Default.GetBytes(inpackage.GetItemKey());
            byte[] ItemKeyLength = BitConverter.GetBytes(ItemKey.Length);
            byte[] Session = Encoding.Default.GetBytes(inpackage.GetSessionCode());
            byte[] SessionLength = BitConverter.GetBytes(Session.Length);
            byte[] ItemId = BitConverter.GetBytes(itemId);
            byte[] UpdateState = BitConverter.GetBytes(false);

            byte[] packagebody = new byte[Username.Length + ItemKey.Length + Session.Length + 17];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(ItemKeyLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(ItemKey, 0, packagebody, Offset, ItemKey.Length);
            Offset += ItemKey.Length;
            Array.ConstrainedCopy(SessionLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Session, 0, packagebody, Offset, Session.Length);
            Offset += Session.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyAddItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_ADD_NEW_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复删除用户分组成功包
        /// </summary>
        /// <param name="inpackage">删除用户分组请求包</param>
        public static void ACK_SucessfulDeleteItem(DeleteItemPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] Session = Encoding.Default.GetBytes(inpackage.GetSessionCode());
            byte[] SessionLength = BitConverter.GetBytes(Session.Length);
            byte[] ItemId = BitConverter.GetBytes(inpackage.GetItemId());
            byte[] UpdateState = BitConverter.GetBytes(true);
            byte[] packagebody = new byte[Username.Length + Session.Length + 13];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(SessionLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Session, 0, packagebody, Offset, Session.Length);
            Offset += Session.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyDeleteItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_DELETE_NEW_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }

        /// <summary>
        ///     回复删除用户分组失败包
        /// </summary>
        /// <param name="inpackage">删除用户分组请求包</param>
        public static void ACK_FailDeleteItem(DeleteItemPacket inpackage)
        {
            byte[] Username = Encoding.Default.GetBytes(inpackage.GetUsername());
            byte[] UsernameLength = BitConverter.GetBytes(Username.Length);
            byte[] Session = Encoding.Default.GetBytes(inpackage.GetSessionCode());
            byte[] SessionLength = BitConverter.GetBytes(Session.Length);
            byte[] ItemId = BitConverter.GetBytes(inpackage.GetItemId());
            byte[] UpdateState = BitConverter.GetBytes(false);
            byte[] packagebody = new byte[Username.Length + Session.Length + 13];
            int Offset = 0;
            Array.ConstrainedCopy(UsernameLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Username, 0, packagebody, Offset, Username.Length);
            Offset += Username.Length;
            Array.ConstrainedCopy(SessionLength, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(Session, 0, packagebody, Offset, Session.Length);
            Offset += Session.Length;
            Array.ConstrainedCopy(ItemId, 0, packagebody, Offset, 4);
            Offset += 4;
            Array.ConstrainedCopy(UpdateState, 0, packagebody, Offset, 1);
            Offset += 1;
            //得到协议
            byte[] protocol1 = ProtocolFactory.ProtocolFactory.GetProtocol("ReplyDeleteItem",
                                                                          (int)Packet.Protocol.OUT_NetworkCommand.REPLY_DELETE_NEW_ITEM_PACKAGE,
                                                                          (int)Packet.Protocol.NetworkProtocol.Base,
                                                                          packagebody,
                                                                          ProtocolFactory.ProtocolFactory.ACK.No,
                                                                          ProtocolFactory.ProtocolFactory.ENCRYPT.No, "");
            NetControl.Send(protocol1, inpackage.GetTalkPort(), inpackage.GetUserIpAddress());
        }
    }
}
